package com.weixing.mall.provider.controller.admin;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.model.dto.CustomerMessageDto;
import com.weixing.mall.provider.model.query.MemberMessageQuery;
import com.weixing.mall.provider.service.ICustomerMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wx
 * @Date 2019/11/22 16:30
 * @Version 1.0
 */
@RestController
@RequestMapping("customerMessage")
@Api(value = "消息Api",tags = "客服消息")
public class CustomerMessageController extends BaseController {

    @Autowired
    private ICustomerMessageService customerMessageService;


    @ApiOperation("查询")
    @GetMapping("")
    public Result selectList(MemberMessageQuery memberMessageQuery){
        return ResultUtil.success(customerMessageService.selectOfPage(initMpPage(),memberMessageQuery));
    }

    @ApiOperation("发布消息")
    @PostMapping
    public Result save(@SysInfo SysAuth auth,@RequestBody CustomerMessageDto customerMessageDto){
        customerMessageService.save(customerMessageDto,auth.getUid());
        return ResultUtil.success();
    }
    @ApiOperation("查询详情")
    @PostMapping("selectDetail/{id}")
    public Result selectDetail(@PathVariable Long id){
        return ResultUtil.success(customerMessageService.getById(id));
    }

    @ApiOperation("删除")
    @PostMapping("del/{id}")
    public Result del(@PathVariable Long id){
        return customerMessageService.removeById(id)  ? ResultUtil.success() : ResultUtil.error();
    }
}
